package com.vhuomai.wechat.service.impl;

import com.quanyue.auto.util.GlobalContext;
import com.vhuomai.wechat.constant.ReplyEvent;
import com.vhuomai.wechat.entity.BaseWxReply;
import com.vhuomai.wechat.mapper.WxReplyMapper;
import com.vhuomai.wechat.service.WxReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author harris
 */
@Service
public class WxReplyServiceImpl implements WxReplyService {
    
    @Autowired
    private WxReplyMapper replyMapper;
    
    @Override
    public BaseWxReply findByEvent(ReplyEvent event, String eventKey) {
        return replyMapper.findByEvent(GlobalContext.merchantNo(), event, eventKey);
    }
    
    @Override
    public List<BaseWxReply> findAll() {
        return replyMapper.findByMerchant(GlobalContext.merchantNo());
    }
    
    @Override
    public BaseWxReply add(BaseWxReply reply) {
        reply.setMerchantNo(GlobalContext.merchantNo());
        reply.setCreateTime(LocalDateTime.now());
        reply.setUpdateTime(reply.getCreateTime());
        replyMapper.insert(reply);
        return reply;
    }
    
    @Override
    public void update(BaseWxReply reply) {
        reply.setUpdateTime(LocalDateTime.now());
        replyMapper.updateSelective(reply);
    }
    
    @Override
    public void remove(int id) {
        replyMapper.deleteOne(id);
    }
}
